# 需求：打开注册A.html页面，完成以下操作：
# 1).点击 alert 按钮
# 2).关闭警告框
# 3).输入用户名：admin

# 导包
import time
from selenium import webdriver
from selenium.webdriver import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options

# 打开浏览器
service = Service(r"D://Python314//chromedriver.exe")
chrome_options = Options()
chrome_options.add_experimental_option("detach", True)
driver = webdriver.Chrome(service=service, options=chrome_options)   # 创建浏览器对象


# 2.输入访问地址（URL）
driver.get("http://121.43.169.97:8848/pageA.html")

# 放大浏览器页面
driver.maximize_window()

# 1).点击 alert 按钮
# driver.find_element_by_css_selector("#alerta").click()
driver.find_element(By.CSS_SELECTOR,"#alerta").click()
time.sleep(2)

# 获取弹框对象
al = driver.switch_to.alert
# 获取文本信息
print("警告框信息:", al.text)
# 处理 对话框
# 1同意
al.accept()


# 2).关闭警告框
# 3).输入用户名：admin
# driver.find_element_by_css_selector("#userA").send_keys("admin")
driver.find_element(By.CSS_SELECTOR,"#userA").send_keys("admin")

# time.sleep(3)
# driver.quit()


# 2取消
# al.dismiss()